package com.haika.demo;

import java.io.File;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.weibo.net.ShareActivity;
import com.weibo.net.Weibo;
import com.weibo.net.WeiboException;

public class DemoShareActivity extends Activity {
    Button btnShare;
    TextView textResult;
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.share);
		btnShare = (Button)findViewById(R.id.btnShare);
		textResult = (TextView)findViewById(R.id.result);
		
		btnShare.setOnClickListener(new OnClickListener(){
			public void onClick(View v){
				File file  = Environment.getExternalStorageDirectory();
				String picPath = file.getAbsolutePath() + "/" + "DCIM/Camera" +  "/" + "test.jpg";
				File picFile = new File(picPath);
				if(!picFile.exists()){
					Toast.makeText(DemoShareActivity.this, "picture not exist", Toast.LENGTH_LONG).show();
					picPath = null;
				}
				try{
					share2weibo("test", picPath);
					Intent intent = new Intent(DemoShareActivity.this, com.weibo.net.ShareActivity.class);
					DemoShareActivity.this.startActivity(intent);
				}catch(Exception e){
					e.printStackTrace();
				}
			}
		});
		
	}
	private void share2weibo(String content, String picPath){
		try{
			Weibo weibo = Weibo.getInstance();
			weibo.share2weibo(this, weibo.getAccessToken().getToken(), weibo.getAccessToken().getSecret(), content, picPath);
		}catch(WeiboException e){
			e.printStackTrace();
		}
		
	}
}
